package main

import (
	"fmt"
	"gorm.io/gorm"
	"mock/gorm_start/ch01"
	"time"
)

type User struct {
	ID        int32     `gorm:"type:int,primarykey"`
	CreatedAt time.Time `gorm:"column:add_time"`
	UpdatedAt time.Time `gorm:"column:update_time"`
	DeletedAt gorm.DeletedAt
	IsDeleted bool
	Mobile    string `gorm:"type:varchar(11),not null"`
	Password  string `gorm:"type:varchar(100),not null"`
	NickName  string `gorm:"type:varchar(20),not null,default''"`
	Birthday  time.Time
	Gender    string
	Role      int32
}

func main() {
	con, err := ch01.NewCon()
	if err != nil {
		panic(err)
	}
	var userList []User
	result := con.Db.Where(&User{Role: 2}).Find(&userList)
	if result.RowsAffected == 0 {
		fmt.Println("数据为空")
		return
	}
	for _, user := range userList {
		fmt.Println(user.NickName)
	}

}
